package com.design.movieticket.service.Impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.design.movieticket.entity.Income;
import com.design.movieticket.entity.Income;
import com.design.movieticket.mapper.IncomeMapper;
import com.design.movieticket.mapper.IncomeMapper;
import com.design.movieticket.service.IncomeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class IncomeServiceImpl extends ServiceImpl<IncomeMapper, Income> implements IncomeService {
    @Resource
    private IncomeMapper incomeMapper;

    /** 分页查询 */
    @Override
    public LambdaQueryWrapper buildQuery(Income income) {
        LambdaQueryWrapper lambdaQueryWrapper = Wrappers.lambdaQuery(Income.class)
                .eq(StringUtils.isNotBlank(income.getIncomeType()),Income::getIncomeType,income.getIncomeType());
        return lambdaQueryWrapper;
    }

    /** 分页相关 */
    @Override
    public <E extends IPage<Income>> E page(E page, Wrapper<Income> queryWrapper) {
        return super.page(page, queryWrapper);
    }

    /** 新增或更新收入数据 */
    @Override
    public void addOrUpdateIncomeInfo(Income income) {
        super.saveOrUpdate(income);
    }

    /** 获取收入信息详情 */
    @Override
    public Income getIncomeDetail(long id) {
        return super.getById(id);
    }

    /** 删除收入信息 */
    @Override
    public void delIncomeById(long id) {
        super.removeById(id);
    }
}
